<?php

namespace app\api\controller\god;

use app\common\controller\Api;

// 招生类型  <=> 报读类型
class Enrollment extends Api
{
    protected $noNeedLogin = ['*'];

    protected $noNeedRight = ['*'];

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model("Enrollment");
    }

    public function lists()
    {
        $params = $this->request->param();
        $lists = $this->model->field('id,name,status')
            ->where('status', 'normal')->select();

        $this->success('查询成功', $lists);

    }

    /**
     * 导航菜单
     * @return void
     */
    public function topnav()
    {
        $lists = $this->model->field('*')
            ->where('index_show', 'normal')
            ->where('status', 'normal')
            ->select();

        foreach ($lists as $k => $item) {
            switch ($item['style_name']) {
                case 'item1':
                    // 推荐院校
                    $item['rec_colleges'] = model('College')->where(['id'=>['in', mb_split(',', $item['rec_colleges'])]])->column('co_name, co_logo', 'id');
                    // 推荐专业
                    $item['rec_profession'] = model('Major')->where(['id'=>['in', mb_split(',', $item['rec_profession'])]])->column('name', 'id');;
                    // 推荐城市
                    $item['rec_city'] = model('College')->where(['id'=>['in', mb_split(',', $item['rec_city'])]])->column('addr_area', 'id');;
                    break;
                case 'item2':
                    // 推荐院校
                    $item['topColleges'] = [];
                    if (!empty($item['top_colleges'])) {
                        $item['topColleges'] = model('College')->where(['id' => ['in', mb_split(',', $item['top_colleges'])]])->select();;
                    }
                    break;
                case 'item3':
                    break;
            }

            // 图片处理
            $item['swiperPics'] = [];
            $item['introductionPics'] = [];
            if (!empty($item['swiper_pics'])) {
                $item['swiperPics'] = mb_split(',', $item['swiper_pics']);
                $item['introductionPics'] = mb_split(',', $item['introduction_pics']);
            }

            $lists[$k] = $item;
        }
        $this->success('查询成功', $lists);
    }
}